import { createSlice, PayloadAction } from '@reduxjs/toolkit'

export type UserStateType = {
  username: string
  nickname: string
}

const INIT_STATE: UserStateType = { username: '', nickname: '' }

export const userSlice = createSlice({
  name: 'user',
  initialState: INIT_STATE,
  reducers: {
    loginReducer: (state: UserStateType, actions: PayloadAction<UserStateType>) => {
      console.log('用户action payload', actions)
      return actions.payload
    },
    logoutReducer: () => INIT_STATE,
  },
})
console.log('11111111111111111111111111111111111', userSlice)
export const { loginReducer, logoutReducer } = userSlice.actions
export default userSlice.reducer
